package com.hdcx.Minfresh.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/23.
 */

public class CartWrapper implements Serializable {

    public List<Cart> carts = new ArrayList<>();

    public void setDataAdd(String id, Integer i, int ps, int is_score, int num) {
        for (int j = 0; j < carts.size(); j++) {
            if (carts.get(j).id.equals(id) && carts.get(j).ps == ps) {
                carts.get(j).num = i+carts.get(j).num >num? num:i+carts.get(j).num;
                return;
            }
        }
        carts.add(new Cart(i, id, ps, is_score));
    }


    public class Cart implements Serializable {
        public String id;//商品id
        public int num;//数量
        public int ps;//配送时间
        public int is_score;//1为积分产品


        public Cart(int num, String id, int ps, int is_score) {
            this.num = num;
            this.id = id;
            this.ps = ps;
            this.is_score = is_score;
        }
    }

    public void setData(String id, int num, int ps, int is_score, int i) {
        for (int j = 0; j < carts.size(); j++) {
            if (carts.get(j).id.equals(id) && carts.get(j).ps == ps) {
                carts.get(j).num = num;
                return;
            }
        }
        carts.add(new Cart(num, id, ps, is_score));
    }
    public int getNumById(String id){
        for (int j = 0; j < carts.size(); j++) {
            if (carts.get(j).id.equals(id)) {

                return carts.get(j).num;
            }
        }
        return 0;
    }
    public void setNumById(String id,int num){
        for (int j = 0; j < carts.size(); j++) {
            if (carts.get(j).id.equals(id)) {
                carts.get(j).num = num;
                return;
            }
        }
    }
    public void deleteBy(String id) {
        for (int j = 0; j < carts.size(); j++) {
            if (carts.get(j).id.equals(id)) {
                carts.remove(j);
                return;
            }
        }
    }

}
